<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Punsub</title>
</head>
<body>
  <!-- <script src="https://cdn.bootcss.com/pubsub-js/1.7.0/pubsub.min.js"></script> -->
  <script src="./PubSub.js"></script>
  <script>

    /* 
    {
      'add':{
        'token1':fn1,
        'token2':fn2
      }
      'remove':{
        'token':fn3
      }
    }
    */

    // 订阅消息
    const token = PubSub.subscribe('add',(msg,data) => {
      console.log('add cb1()',msg,data)
    })
    PubSub.subscribe('add',(msg,data) => {
      console.log('add cb2()',msg,data)
    })
    PubSub.subscribe('remove',(msg,data) => {
      console.log('remove cb1()',msg,data)
    })
    // PubSub.unsubscribe(token)
    PubSub.publish('add',1)
    PubSub.publishSync('add',2)
    console.log('add 之后');
    PubSub.publish('remove',3)

  </script>
</body>
</html>